package o13addone;

/**
 * @author shkstart
 * @create 2022-01-09-18:44
 */
public class AddOne {

    public static int sign = 0;

    public static void main(String[] args) {
        int[] digits = {5, 9, 9};
        int[] ints = plusOne(digits);
        for (int anInt : ints) {
            System.out.print(anInt);
        }
    }

    public static int[] plusOne(int[] digits) {

        if (digits[digits.length - 1] != 9) {
            digits[digits.length - 1] += 1;
        } else {
            addOne(digits,0);
        }
        return digits;

    }


    public static int addOne(int[] digits, int i) {

        i++;
        sign = 0;

        if (i < digits.length) {
            addOne(digits, i);
        }

        if (digits[i - 1] == 9) {
            sign = 1;
            digits[i - 1] = 0;
            return sign;
        } else {
            digits[i - 1] += sign;
            sign = 0;
            return sign;
        }


    }
}
